package com.nf.action;

import com.nf.entity.Account;
import com.nf.entity.Record;
import com.nf.service.AccountService;
import org.omg.CORBA.Request;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class AccountAction {

    @Autowired
    private AccountService accountService;


    @RequestMapping("/kkk")
    public String test1(Model model){
        Account account = accountService.login("钟林", "135376");
        if (account==null){
            return "loginError";
        }
        model.addAttribute("account",account);
        return "index";
    }

    @ResponseBody
    @RequestMapping("/kkk2")
    public Record test2(){
        Integer banlance = accountService.queryBanlanceById(1);
        System.out.println(banlance);
        return null;
    }


    @ResponseBody
    @RequestMapping("/kkk3")
    public Record test3(){
        boolean b = accountService.updatePassword("999999","135376",2);
        return null;
    }

    @ResponseBody
    @RequestMapping("/kkk4")
    public Record test4(){
        boolean b = accountService.saveMoney(500,1);
        return null;
    }

    @ResponseBody
    @RequestMapping("/kkk5")
    public Record test5(){
        boolean b = accountService.getMoney(1500,2);
        return null;
    }

    @ResponseBody
    @RequestMapping("/kkk6")
    public Record test6(){
        boolean b = accountService.transMoney(1000000,1,2);
        return null;
    }

    @RequestMapping("/kkk7")
    public String test7(Integer id){
        System.out.println("id:"+id);
        return "abc";
    }
    @RequestMapping("/login")
    public String test8(Integer id){
        System.out.println("id:"+id);
       return "login";
    }

    @RequestMapping("/myLogin")
    public String test9(String username,String password,Model model){
       Account account=accountService.login(username,password);
       if(account==null){
           return "loginError";
       }else{
           System.out.println(account.getUserName()+" , "+account.getBalance());
           model.addAttribute("account",account);
           return "1234";
       }
    }
    @RequestMapping("/kkkk1")
    public String test10(Account account ,Model model){
        account.setCardNo("888-888888");
        model.addAttribute("account",account);
        return "kk";
    }
    @RequestMapping("/kkkk2")
    public String test11(Account account,Model model){
        model.addAttribute("account",account);
        return "kk2";
    }
}
